<template>
  <div class="install">
    <Vheader title="修改密码"></Vheader>
    <section class="main">
      <div class="input-box">
        <label class="input-label flex2">当前密码:</label>
        <input type="password" class="input flex8" v-model="password" @blur="checkPass(password)"
               placeholder="请输入当前密码">
      </div>
      <div class="input-box">
        <label class="input-label flex2">新密码:</label>
        <input type="password" class="input flex8" v-model="newPassword" @blur="checkPass(newPassword)"
               placeholder="请输入6-16位新密码">
      </div>
      <div class="input-box">
        <label class="input-label flex2">确认密码:</label>
        <input type="password" class="input flex8" v-model="confirmPassword"
               @blur="checkConPass(newPassword,confirmPassword)" placeholder="请再次输入新密码">
      </div>
      <mt-button @click.native="updatePass" type="primary" class="exit">确认</mt-button>
    </section>
  </div>
</template>

<script>
  import {Toast} from 'mint-ui'
  import Vheader from '../../components/header'
  import axios from '../../axios/axios'
  export default{
    data () {
      return {
        password: '',
        newPassword: '',
        confirmPassword: ''
      };
    },
    methods: {
      updatePass() {
        var that=this;
        var dataPass = JSON.stringify({
          'data': [{
            'password': this.password,
            'newPassword': this.newPassword
          }],
          'controllerName': 'userInfo',
          'actionName': 'updatePassword'
        });
        console.log(this.checkPass(this.password));
        console.log(this.checkPass(this.newPassword));
        console.log(this.checkConPass(this.newPassword, this.confirmPassword));
        if (this.checkPass(this.password) && this.checkPass(this.newPassword) && this.checkConPass(this.newPassword, this.confirmPassword)) {
          axios.postAdmain({
            data:dataPass,
            callback(response){
              if (response.data.data.result === true) {
                Toast(response.data.data.remark);
                that.$router.push('/user');
              } else {
                Toast(response.data.data.data);
              }
              console.log(response.data);
            }
          })
        } else {
          Toast('输入格式有误');
        }
      },
      checkPass(pass) {
        var expPass = /^(\w){6,16}$/;
        if (!expPass.test(pass)) {
          this.$dialog.toast({mes: '密码要为6~16位数字，字母下划线组成'});
          return false;
        } else {
          return true;
        }
      },
      checkConPass(pass1, pass2) {
        if (pass1 !== pass2) {
          this.$dialog.toast({mes: '密码和之前密码不一致'});
          return false;
        } else {
          return true;
        }
      }
    },
    components: {
      Vheader
    }
  };
</script>
<style type="text/scss" lang="scss" scoped>
  @import "../../common/style/public";
</style>







